package com.shanglida.guide;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.shanglida.R;
import com.shanglida.adapt.ViewPagerAdapter;

/**
 * @author liu
 * @deprecated 第一次启动的界面
 * @version 2.0
 * @date 2014-03-05
 * @copyright 广州尚礼达
 */
public class LeadActivity extends Activity {
	// 定义ViewPager对象
	private ViewPager viewPager;

	// 定义ViewPager适配器
	private ViewPagerAdapter vpAdapter;

	// 定义一个ArrayList来存放View
	private ArrayList<View> views;

	// 定义各个界面View对象
	private View view1, view2, view3, view4;

	// 定义底部小点图片
	private ImageView point_a, point_b, point_c, point_d;

	// 定义开始按钮对象
	private Button startBt;

	// 当前的位置索引值
	private int currIndex = 0;

	/*
	 * initView 初始化组件 initData 监听
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initData();

	}

	/**
	 * 初始化组件
	 */
	private void initView() {
		// 实例化各个界面的布局对象
		LayoutInflater mLi = LayoutInflater.from(this);
		view1 = mLi.inflate(R.layout.guide_view01, null);
		view2 = mLi.inflate(R.layout.guide_view02, null);
		view3 = mLi.inflate(R.layout.guide_view03, null);
		view4 = mLi.inflate(R.layout.guide_view04, null);

		// 实例化ViewPager
		viewPager = (ViewPager) findViewById(R.id.viewpager);

		// 实例化ArrayList对象
		views = new ArrayList<View>();

		// 实例化ViewPager适配器
		vpAdapter = new ViewPagerAdapter(views);

		// 实例化底部小点图片对象
		point_a = (ImageView) findViewById(R.id.page0);
		point_b = (ImageView) findViewById(R.id.page1);
		point_c = (ImageView) findViewById(R.id.page2);
		point_d = (ImageView) findViewById(R.id.page3);

		// 实例化开始按钮
		startBt = (Button) view4.findViewById(R.id.startBtn);
	}

	/**
	 * 监听
	 */
	private void initData() {
		// 设置监听
		viewPager.setOnPageChangeListener(new MyOnPageChangeListener());
		// 设置适配器数据
		viewPager.setAdapter(vpAdapter);

		// 将要分页显示的View装入数组中
		views.add(view1);
		views.add(view2);
		views.add(view3);
		views.add(view4);

		// 给开始按钮设置监听
		startBt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				StartMain();
			}
		});
	}

	/**
	 * @author liu
	 * @deprecated 页卡切换
	 */
	public class MyOnPageChangeListener implements OnPageChangeListener {
		@Override
		public void onPageSelected(int position) {
			switch (position) {
			case 0:
				point_a.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_focused));
				point_b.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				break;
			case 1:
				point_b.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_focused));
				point_a.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				point_c.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				break;
			case 2:
				point_c.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_focused));
				point_b.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				point_d.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				break;
			case 3:
				point_d.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_focused));
				point_c.setImageDrawable(getResources().getDrawable(
						R.drawable.page_indicator_unfocused));
				break;
			}
			currIndex = position;
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {

		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {

		}
	}

	/**
	 * 相应按钮点击事件
	 */
	private void StartMain() {
		Intent intent = new Intent();
		intent.setClass(LeadActivity.this, MainActivity.class);
		startActivity(intent);
		this.finish();
	}

}
